package com.github.ghsea.sso.client.security.permission.http;

import com.github.ghsea.sso.client.config.ShiroConfig;
import com.github.ghsea.sso.client.security.permission.User;
import com.github.ghsea.sso.client.security.permission.UserManager;
import com.google.gson.reflect.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author guhai
 */
@Service(value = "UserManagerHttpImpl")
public class UserManagerHttpImpl extends AbstractRestInvoker<User> implements UserManager {

    @Autowired
    private ShiroConfig shiroConfig;

    @Override
    public User queryByMail(String mail) {
        String apiUrlGetUser = shiroConfig.getApiUrlGetUser();
        String url = apiUrlGetUser.replaceAll(" ", "").replace("{mail}", mail);
        return super.invoke(url);
    }

    @Override
    TypeToken responseTypeToken() {
        return new TypeToken<RestResponse<User>>() {
        };
    }
}
